package com.mingqi.enetconnected.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.mingqi.enetconnected.R;


/**
 * @author yaxi
 * @date 2018/9/17
 */
public class DottedLine extends View {
    private int left,right,bottom;
    private Paint mPaint;

    private int dottedLineCellWidth = 20;

    public DottedLine(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DottedLine(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);init();
    }

    public DottedLine(Context context) {
        super(context);init();
    }

    void init(){


        mPaint = new Paint();
        mPaint.setColor(getResources().getColor(R.color.space));
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        left = 0;
        right = w;
        bottom = h;
        mPaint.setStrokeWidth(h);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int count = (right - left)/dottedLineCellWidth/2;
        for (int j = 0; j < count; j++) {
            int start = left + j * dottedLineCellWidth * 2;
            int end = start + dottedLineCellWidth;
            float[] pts = new float[]{start,0,end,0};
            canvas.drawLines(pts,mPaint);
        }
    }
}
